﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;

public class Resource : NetworkBehaviour
{
    #region 单例
    public static Resource instance;
    #endregion
    public int soldierNum;
    public int coinNum;
    public int population;

    private void Awake()
    {
        instance = this;
        soldierNum = 0;
        coinNum = 0;
        population = 0;
    }
    void OnEnable()
    {
        EventManager.Instance.AddListener<CreatSoldierEvent>(AddSoldier);
    }

    private void AddSoldier(CreatSoldierEvent e)
    {
        soldierNum++;
    }

    public void AddCoin(int n)
    {
        coinNum += n;
    }

    public void UseCoin(int n)
    {
        coinNum -= n;
        if (coinNum < 0)
        {
            coinNum = 0;
        }
    }

    void OnDisable()
    {
        EventManager.Instance.RemoveListener<CreatSoldierEvent>(soldierDead);
    }

    private void soldierDead(CreatSoldierEvent e)
    {
        soldierNum--;
    }

}
